package cn.com.nes.site.action.templetedesign;


import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.service.templatedesign.HHousedesignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;


@Controller
@RequestMapping("/house")
public class HHousedesignController {
    
    @Autowired
    private HHousedesignService hHousedesignService;
    
    /**
     * 订单池/我的订单/审核列表
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/orders", method = RequestMethod.POST)
    @ResponseBody
    public PageData orders(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.getCustomerClaim(req);
    }

    /**
     * 添加订单
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/addorder", method = RequestMethod.POST)
    public @ResponseBody PageData addOrder(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.addOrder(req);
        
        
    }
    
    /**
     * 订单详情
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/orderdetails", method = RequestMethod.POST)
    public @ResponseBody PageData orderDetails(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.orderDetails(req);
    }
    
    /**
     * 接单
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/takeorders", method = RequestMethod.POST)
    public @ResponseBody PageData takeOrders(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.takeOrders(req);
    }
    
    /**
     * 删除订单
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/deleteorder", method = RequestMethod.POST)
    @ResponseBody
    public PageData deleteOrder(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.deleteOrder(req);
    }
    
    /**
     * 施工进度查询
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/progressqueries", method = RequestMethod.POST)
    @ResponseBody
    public PageData progressQueries(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.progressQueries(req);
    }
    
    /**
     * 设计结果上传
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/outcome",method = RequestMethod.POST)
    @ResponseBody
    public PageData outcome(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.outcome(req);
    }
    
    /**
     * 订单审核
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/audit",method = RequestMethod.POST)
    @ResponseBody
    public PageData audit(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.audit(req);
    }
    
    /**
     * 退单
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/chargebacks",method = RequestMethod.POST)
    @ResponseBody
    public PageData chargebacks(HttpServletRequest request, HttpServletResponse response) {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        return hHousedesignService.chargebacks(req);
    }
}